package com.yuncheng.spcyApi.controller;

import com.yuncheng.annotation.AutoLog;
import com.yuncheng.spcyApi.mapper.DictItemMapper;
import com.yuncheng.spcyApi.service.IDictItemService;
import com.yuncheng.spcyApi.vo.common.DictItemVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "数据字典-接口")
@RestController
@RequestMapping(value = "/api/spzx-spcy/dict")
public class DictItemController {

    @Resource
    private IDictItemService dictItemService;

    @Resource
    private DictItemMapper dictItemMapper;

    @AutoLog(value = "查询数据字典明细查询-根据数据字典名称")
    @ApiOperation(value = "查询数据字典明细查询-根据数据字典名称")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "dictName",value = "字典名称",dataType = "String",required = true)
    })
    @GetMapping(value = "/getDictListByDictName")
    public HttpResult<?> getDictListByDictName(@RequestParam(value = "dictName",required = false)String dictName){
        if (StringUtils.isEmpty(dictName)){
            return HttpResult.ok("字典名称不能为空");
        }
        List<DictItemVo> dictItemByName = dictItemService.getDictItemByName(dictName);
        return HttpResult.ok(dictItemByName);
    }

    @AutoLog(value = "查询数据字典明细查询-根据数据字典编码")
    @ApiOperation(value = "查询数据字典明细查询-根据数据字典编码")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "dictCode",value = "字典编码",dataType = "String",required = true)
    })
    @GetMapping(value = "/getDictListByDictCode")
    public HttpResult<?> getDictListByDictCode(@RequestParam(value = "dictCode",required = false)String dictCode){
        if (StringUtils.isEmpty(dictCode)){
            return HttpResult.ok("字典编码不能为空");
        }
        List<DictItemVo> dictItemByName = dictItemMapper.getDictItemByCode(dictCode);
        return HttpResult.ok(dictItemByName);
    }

}
